<?

class myGoogle {
	
	protected $request = NULL;
	protected $result = NULL;
	
	function __construct(){
	
	}	
	
	function doRequest($request){
		
		$request_encoded = urlencode($request);
		
		$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
			. "q=" . $request_encoded . "&userip=USERS-IP-ADDRESS";
		
		// sendRequest
		// note how referer is set manually
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_REFERER, 'http://www.sb-web.net/');
		$body = curl_exec($ch);
		curl_close($ch);
		
		// now, process the JSON string
		$json = json_decode($body, true);
		// now have some fun with the results...
		
		$this->result = $json;
		return $json;
	}
	
	function get_facebook_page(){
						
		foreach($this->result['responseData']['results'] as $row){
			if(eregi('www.facebook.com', $row['unescapedUrl']) ){
				return $row['unescapedUrl'];
			}
		}
		
		return false;
	}
	
	function get_twitter_page(){
						
		foreach($this->result['responseData']['results'] as $row){
			if(eregi('twitter.com', $row['unescapedUrl']) ){
				return $row['unescapedUrl'];
			}
		}
		
		return false;
	}
		
	
}

?>